home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / os2 / pccts.zip / GLOBALS.C < prev    next >
C/C++ Source or Header  |  1992-12-08  |  7KB  |  172 lines

  1. /*
  2.  * globals.c    --    File containing all variables/tables visible to all files.
  3.  *
  4.  * SOFTWARE RIGHTS
  5.  *
  6.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  7.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  8.  * company may do whatever they wish with source code distributed with
  9.  * PCCTS or the code generated by PCCTS, including the incorporation of
  10.  * PCCTS, or its output, into commerical software.
  11.  * 
  12.  * We encourage users to develop software with PCCTS.  However, we do ask
  13.  * that credit is given to us for developing PCCTS.  By "credit",
  14.  * we mean that if you incorporate our source code into one of your
  15.  * programs (commercial product, research project, or otherwise) that you
  16.  * acknowledge this fact somewhere in the documentation, research report,
  17.  * etc...  If you like PCCTS and have developed a nice tool with the
  18.  * output, please mention that you developed it using PCCTS.  In
  19.  * addition, we ask that this header remain intact in our source code.
  20.  * As long as these guidelines are kept, we expect to continue enhancing
  21.  * this system and expect to make other tools available as they are
  22.  * completed.
  23.  *
  24.  * Terence Parr
  25.  * Purdue University
  26.  * August 1990
  27.  */
  28. #include <stdio.h>
  29. #include "set.h"
  30. #include "syn.h"
  31. #include "hash.h"
  32. #include "generic.h"
  33.  
  34. char Version[] = "1.06";    /* PCCTS version number */
  35. char LexStartSymbol[] = "START";/* Name of starting lexical class/automaton */
  36.  
  37. char *DlgFileName = "parser.dlg";
  38. char *DefFileName = "tokens.h";
  39. char *ErrFileName = "err.c";
  40.  
  41.  
  42. /* Current ambiguity examination information */
  43. int CurAmbigAlt1, CurAmbigAlt2, CurAmbigline, CurAmbigfile;
  44. char *CurAmbigbtype;
  45.  
  46.  
  47.                         /* M e t h o d  T a b l e s */
  48. /*
  49.  * The following tables are used to fill syntax diagram nodes with the correct
  50.  * function pointers for computing FIRST sets and printing themselves.
  51.  */
  52.  
  53. /* fpTraverse[node type] == pointer to function that calculates trees
  54.  * representing the FIRST sets for that node (maintains spatial info).
  55.  */
  56. Tree *(*fpTraverse[NumNodeTypes+1])() = {
  57.     NULL,
  58.     tJunc,
  59.     tRuleRef,
  60.     tToken,
  61.     tAction
  62. };
  63.  
  64. /* fpReach[node type] == pointer to function that calculates FIRST set for
  65.  * that node. (r stands for reach)
  66.  */
  67. set (*fpReach[NumNodeTypes+1])() = {
  68.     NULL,
  69.     rJunc,
  70.     rRuleRef,
  71.     rToken,
  72.     rAction
  73. };
  74.  
  75. /* fpPrint[node type] == pointer to function that knows how to print that node. */
  76. void (*fpPrint[NumNodeTypes+1])() = {
  77.     NULL,
  78.     pJunc,
  79.     pRuleRef,
  80.     pToken,
  81.     pAction
  82. };
  83.  
  84. char *decodeJType[] = {
  85.     "invalid",
  86.     "aSubBlk",
  87.     "aOptBlk",
  88.     "aLoopBlk",
  89.     "EndBlk",
  90.     "RuleBlk",
  91.     "Generic",
  92.     "EndRule",
  93.     "aPlusBlk",
  94.     "aLoopBegin"
  95. };
  96.  
  97.  
  98.                             /* H a s h  T a b l e s */
  99.  
  100. Entry    **Tname,            /* Table of all token names (maps name to tok num)*/
  101.         **Texpr,            /* Table of all token expressions
  102.                                (maps expr to tok num) */
  103.         **Rname,            /* Table of all Rules (has ptr to start of rule) */
  104.         **Fcache,            /* Cache of First/Follow Computations */
  105.         **Tcache;            /* Tree cache; First/Follow for permute trees */
  106.  
  107.  
  108.                             /* V a r i a b l e s */
  109.  
  110. int        EpToken=0;            /* Imaginary Epsilon token number */
  111. int        CurFile= -1;        /* Index into FileStr table */
  112. char    *CurRule=NULL;        /* Pointer to current rule name */
  113. RuleEntry *CurRuleNode=NULL;/* Pointer to current rule node in syntax tree */
  114. char    *CurRetDef=NULL;    /* Pointer to current return type definition */
  115. char    *CurParmDef=NULL;    /* Pointer to current parameter definition */
  116. int        NumRules=0;            /* Rules are from 1 to n */
  117. FILE    *output=NULL;        /* current parser output file */
  118. FILE    *input=NULL;        /* current grammar input file */
  119. char    *FileStr[MaxNumFiles];/* Ptr to array of file names on command-line */
  120. int        NumFiles=0;            /* current grammar file number */
  121. void    (**fpTrans)(),        /* array of ptrs to funcs that translate nodes */
  122.          (**fpJTrans)();        /*  ... that translate junctions */
  123. int        **FoStack;            /* Array of LL_k ptrs to stacks of rule numbers */
  124. int        **FoTOS;            /* FOLLOW stack top-of-stack pointers */
  125. Junction *SynDiag = NULL;    /* Pointer to start of syntax diagram */
  126. int        BlkLevel=1;            /* Current block level.  Set by antlr.g, used by
  127.                              * scanner to translate $i.j attributes */
  128. int        TokenNum=TokenStart;
  129. char    **TokenStr=NULL;    /* map token # to token name */
  130. char    **ExprStr=NULL;        /* map token # to expr */
  131. Junction **RulePtr=NULL;    /* map rule # to RuleBlk node of rule */
  132. ListNode *ExprOrder=NULL;    /* list of exprs as they are found in grammar */
  133. ListNode *BeforeActions=NULL;/* list of grammar actions before rules */
  134. ListNode *AfterActions=NULL;/* list of grammar actions after rules */
  135. ListNode *LexActions=NULL;    /* list of lexical actions */
  136. ListNode **Cycles=NULL;        /* list of cycles (for each k) found when
  137.                                doing FOLLOWs */
  138. ListNode *eclasses=NULL;    /* list of error classes */
  139. LClass     lclass[MaxLexClasses]; /* array of lex class definitions */
  140. int         CurrentLexClass;    /* index into lclass */
  141. int         NumLexClasses=0;    /* in range 1..MaxLexClasses (init 0) */
  142.  
  143. char    *HdrAction=NULL;    /* action defined with #header */
  144. FILE    *ErrFile;            /* sets and error recovery stuff */
  145. FILE    *DefFile=NULL;        /* list of tokens, return value structs, setwd defs */
  146. int        CannotContinue=FALSE;
  147. int        OutputLL_k = 1;        /* LL_k for parsing must be power of 2 */
  148. int        action_file;        /* used to track start of action */
  149. int        action_line;
  150.  
  151.                         /* C m d - L i n e  O p t i o n s */
  152.  
  153. int        LL_k=1;                /* how many tokens of lookahead */
  154. int        PrintOut = FALSE;    /* print out the grammar */
  155. int        PrintAnnotate = FALSE;/* annotate printout with FIRST sets */
  156. int        CodeGen=TRUE;        /* Generate output code? */
  157. int        LexGen=TRUE;        /* Generate lexical files? (tokens.h, parser.dlg) */
  158. int        GenAST=FALSE;        /* Generate AST's? */
  159. int        GenANSI=FALSE;        /* Generate ANSI code where necessary */
  160. int        GenExprSets=TRUE;    /* use sets not (LA(1)==tok) expression lists */
  161. int        GenCR=FALSE;        /* Generate cross reference? */
  162. int        GenLineInfo=FALSE;    /* Generate # line "file" stuff? */
  163. int        TraceGen=FALSE;        /* Generate code to trace rule invocation */
  164. int        elevel=1;            /* error level for ambiguity messages */
  165. int        GenEClasseForRules=0;/* don't generate eclass for each rule */
  166. int        TreeResourceLimit= -1;/* don't limit tree resource */
  167. int        DemandLookahead = 0;/* demand/delayed lookahead or not */
  168. char    *RulePrefix = "";    /* prefix each generated rule with this */
  169. char    *stdpccts = "stdpccts.h";/* where to generate std pccts include file */
  170. int        GenStdPccts = 0;    /* don't gen stdpccts.h? */
  171. int        ParseWithPredicates = 0;    /* don't use for version 1.06 */
  172.